<template>
	<view class="index-box">
		<sww-nav-bar v-show="navInit" :borderBottom="false" :title="title" :background="bgColor || '#ffffff'" :titleColor="fColor || '#000000'"></sww-nav-bar>
		<home-page v-if="pageId?true:false" :pageId="pageId" ref="modulePageRef" @changNav="changNav" @changTopic="changTopic"></home-page>
		<template v-for="(item,index) in pageIds">
			<home-page v-show="currentIndex === index" :key="index" :ref="'moduleOther_' + index" :pageId="item" :autoInit="false"></home-page>
		</template>
		<sww-sidebar v-if="navInit" :scroll-top="scrollTop" :contact='contact' :hasTop="hasTop"></sww-sidebar>
		<sww-login></sww-login>
	</view>
</template>
<script>
import { pageShare } from '../../mixins/pageShare';
import homePage from '@/pagecomponents/homePage/homePage';
import { mapState } from 'vuex';
export default {
	mixins: [pageShare],
	props: {
		tabIndex:{
			type:Number,
			default:0
		}
	},
	data() {
		return {
			pageIds: [],
			currentIndex: 0,
			scrollTop: 0,
			bgColor: '',
			fColor:'',
			contact:false,
			hasTop:false,
			navInit: false,
			title:'',
			pageId:null
		};
	},
	components: { homePage },
	computed: {
		...mapState(['vuex_tab_bar'])
	},
	mounted () {
		let obj = this.vuex_tab_bar.list[this.tabIndex]
		this.title = obj.query.title || obj.text
		this.pageId = Number(obj.query.id || 0)
	},
	methods: {
		changNav(item) {
			this.hasTop = item.hasTop
			this.bgColor = item.bgColor;
			this.fColor = item.fColor;
			this.navInit = true;
		},
		changTopic (obj) {
			if (obj.arrid) {
				this.pageIds = [].concat(obj.arrid)
			}
			this.currentIndex = obj.index
			this.$nextTick(() => {
				let str = 'moduleOther_' + obj.index
				if (this.$refs[str][0].manualInit) {
					this.$refs[str][0].manualInit();
				}
			})
		},
		$onLoad() {},
		$onShow() {
			this.shareOnshow()
		},
		$onHide() {},
		$onPullDownRefresh() {
			this.pageIds = []
			if (this.$refs.modulePageRef.$onPullDownRefresh) {
				this.$refs.modulePageRef.$onPullDownRefresh();
			}
		},
		$onReachBottom() {
			let str = 'moduleOther_' + this.currentIndex
			if (!this.pageIds[0] && this.$refs.modulePageRef.$onReachBottom) {
				this.$refs.modulePageRef.$onReachBottom();
			} else if (this.$refs[str][0] && this.$refs[str][0].$onReachBottom) {
				this.$refs[str][0].$onReachBottom();
			}
		},
		$onPageScroll(e) {
			this.scrollTop = e.scrollTop
		},
	}
};
</script>

<style scoped lang="scss">
</style>
